package com.hooker.view

import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import android.os.Looper
import android.util.DisplayMetrics
import android.view.Window
import android.view.WindowManager
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import com.hooker.settings.SettingHelper
import com.hooker.util.Constants
import com.sdk.hooker.penetration.R

class MailDialog : Dialog {

    private lateinit var tvTitle: TextView
    private lateinit var editMail: EditText
    private lateinit var btnAdd: Button

    constructor(context: Context) : this(context, R.style.dialog)
    constructor(context: Context, themeResId: Int) : super(context, themeResId) {
        setContentView(R.layout.dialog_mail)
        setCancelable(true)
        initParams()
        initView()
        initData()
    }

    private fun initParams() {
        var dp = DisplayMetrics()
        window?.windowManager?.defaultDisplay?.getMetrics(dp)
        var width = dp.widthPixels
        window?.setLayout(width * 4 / 5, WindowManager.LayoutParams.WRAP_CONTENT)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    private fun initView() {
        tvTitle = findViewById(R.id.title_id)
        editMail = findViewById(R.id.edit_mail)
        btnAdd = findViewById(R.id.btn_add_mail)
        btnAdd.setOnClickListener {
            var email = editMail.text.toString()
            if ("" == email) {
                SettingHelper.putInfo(context, Constants.MAIL_TAG_ID, email)
            }
        }
    }

    private fun initData() {
        tvTitle.text = "添加邮箱联系人"
    }

}